//
//  TTHomeViewCell.m
//  TTWeibo
//
//  Created by 陶宏路 on 16/7/27.
//  Copyright © 2016年 陶路路. All rights reserved.
//

#import "TTHomeViewCell.h"
#import "TTHeadView.h"
#import "TTHomeVcModel.h"
#import "TTCenterView.h"
#import "TTbottomBarView.h"
#import "TTOtherView.h"
@interface TTHomeViewCell ()

@property (nonatomic,strong) TTHeadView * headView;
@property (nonatomic,strong) TTCenterView * centerView;
@property (nonatomic,strong) TTbottomBarView * bottonBar;
@property (nonatomic,strong) TTOtherView * otherView;
@property (nonatomic,strong) MASConstraint * constraint;

@end
@implementation TTHomeViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setUpUI];
        [self setUpLayout];
    }
    
    return self;
}

#pragma mark 懒加载
-(TTHeadView *)headView{
    
    if (_headView == nil) {
        
        _headView = [[TTHeadView alloc]init];
    }
    
    return _headView;
}

-(TTCenterView *)centerView{
    
    if (_centerView == nil) {
        
        _centerView = [[TTCenterView alloc]init];
    }
    
    return _centerView;
}

-(TTbottomBarView *)bottonBar{
    
    if (_bottonBar == nil) {
        
        _bottonBar = [[TTbottomBarView alloc]init];
    }
    
    return _bottonBar;
}

-(TTOtherView *)otherView{
    
    if (_otherView == nil) {
        
        _otherView = [[TTOtherView alloc]init];
    }
    
    return _otherView;
}

-(void)setUpUI{
    
    [self.contentView addSubview:self.headView];
    [self.contentView addSubview:self.centerView];
    [self.contentView addSubview:self.bottonBar];
    [self.contentView addSubview:self.otherView];
}

-(void)setUpLayout{
    
    [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.leading.trailing.equalTo(self.contentView);
    }];
    
    [self.centerView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.headView.mas_bottom).offset(10);
        make.leading.trailing.equalTo(self.contentView);
    }];
    
    
    
    [self.otherView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.centerView.mas_bottom).offset(10);
        make.leading.trailing.equalTo(self.contentView);
    }];
    
    [self.bottonBar mas_makeConstraints:^(MASConstraintMaker *make) {
        
        self.constraint = make.top.equalTo(self.otherView.mas_bottom);
        make.leading.trailing.equalTo(self.contentView);
        make.height.equalTo(@(35));
    }];
    
#pragma mark 设置自身约束 用 contentView
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.leading.trailing.top.equalTo(self);
        make.bottom.equalTo(self.bottonBar);
    }];
}

-(void)setCellModel:(TTHomeCellModel *)cellModel{
    
    _cellModel = cellModel;
    
    self.headView.headModel = cellModel;
    self.centerView.centerModel = cellModel;
    
    [self.constraint uninstall];
    
    if (cellModel.cellModel.retweeted_status.pictureArray == nil) {
        
        [self.bottonBar mas_updateConstraints:^(MASConstraintMaker *make) {
           
            self.constraint = make.top.equalTo(self.centerView.mas_bottom);
        }];
        
        self.otherView.hidden = YES;
        
    }else{
        
        self.otherView.otherModel = cellModel;
        
        [self.bottonBar mas_updateConstraints:^(MASConstraintMaker *make) {
           
            self.constraint = make.top.equalTo(self.otherView.mas_bottom);
        }];
        
        self.otherView.hidden = NO;
    }
}

@end
